use std::fmt::{Display, Formatter};
use clap::Parser;

use super::check_input_file_path;

#[derive(Debug, Parser)]
pub struct Base64Opts {
    #[arg(short, long, value_parser = parse_type, alias = "type")]
    pub base_type: BaseType,

    #[arg(short, long, value_parser = parse_base64_format)]
    pub format: Base64Format,
    #[arg(short, long, default_value = "-"  , value_parser = check_input_file_path)]
    pub input: String,

}


#[derive(Debug, Copy, Clone)]
pub enum BaseType {
    Encode,
    Decode,

}

#[derive(Debug, Copy, Clone)]
pub enum Base64Format {
    STANDARD,
    URL,
}


fn parse_type(type_str: &str) -> anyhow::Result<BaseType, String> {
    match type_str {
        "encode" => Ok(BaseType::Encode),
        "decode" => Ok(BaseType::Decode),
        _ => Err("NOT_SUPPORT".to_string())
    }
}


fn parse_base64_format(format_str: &str) -> anyhow::Result<Base64Format, String> {
    match format_str {
        "standard" => Ok(Base64Format::STANDARD),
        "url" => Ok(Base64Format::URL),
        _ => Err("NOT_SUPPORT".to_string())
    }
}



